package factories;

import gui.BackgroundType;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.*;

import statics.Constants;

public class TestRenderer extends JFrame implements KeyListener{

	public static void main(String[] args){
		new TestRenderer();
	}
	
	private Container cp;
	private MapRenderer world;
	private RandomWorldGenerator rwg;
	private char direction;
	private Timer timer;
	
	public TestRenderer(){
		super("Random World Generator v0.1");
		setVisible(true);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setPreferredSize(new Dimension(1000,800));
		setResizable(false);
		
		cp = getContentPane();
		cp.setLayout(null);
		world = new MapRenderer();
		world.setBounds(0,0,1000,800);
		
		timer = new Timer(200,new EasyKeyScrollListener(world, this));
		addKeyListener(this);
		
		rwg = new RandomWorldGenerator();
		
		//BackgroundType t = BackgroundType.GRASS;
		
		//Ask for dimension
		int x = Integer.parseInt(JOptionPane.showInputDialog("Geef x dimensiewaarde in", String.valueOf(Constants.tile_x)));
		int y = Integer.parseInt(JOptionPane.showInputDialog("Geef y dimensiewaarde in", String.valueOf(Constants.tile_y)));
		rwg.initialize(x,y);
		world.setMap(rwg.getMap());
		
		//Ask for stone chance percentage
		int p = Integer.parseInt(JOptionPane.showInputDialog("Geef rock percentage in", String.valueOf(0)));
		int s = Integer.parseInt(JOptionPane.showInputDialog("Geef rock scatterness in", String.valueOf(0)));
		rwg.createLayerOne(p,s);
		world.setMap(rwg.getMap());
		
		
		cp.add(world);
		pack();
	}

	public char getDirection() {
		return direction;
	}

	@Override
	public void keyPressed(KeyEvent arg) {
		direction = arg.getKeyChar();
		timer.start();
	}

	@Override
	public void keyReleased(KeyEvent arg0) {
		timer.stop();
	}

	@Override
	public void keyTyped(KeyEvent arg) {
		char c = arg.getKeyChar();
		switch(c){
			case 'z' : world.shiftTop(); break;
			case 's' : world.shiftBottom(); break;
			case 'q' : world.shiftLeft(); break;
			case 'd' : world.shiftRight(); break;
		}
		
	}
	
}
